<?php
namespace app\admin\api;

use think\Controller;
use \think\Session;
use app\admin\common\Http\ConferenceHttpClient;

//邮件模板接口类
class ConferenceEmail extends ConferenceHttpClient
{

    /**
     * 获取会议站邮件模板列表
     * @return [type] [description]
     */
    public function emailList($token,$data)
    {
        //获取数据
        $url = '/v1/site/emails';

        $res['page'] = $data['page'];
        $res['page_size'] = $data['limit'];

        //设置headers头
        $headers = getheader($token);

        //请求接口信息
        $result = $this->get($url,$res,$headers);

        if ($result->code == 0){
            return $result->data;

        }else{
            return $result->message;
        }
    }


    /**
     * 会议站邮件模板创建
     * @return [type] [description]
     */
    public function emailCreate($data,$token)
    {
        $url = '/v1/site/emails';

        //设置headers头
        $headers = getheader($token);

        //请求接口信息
        $result = $this->post($url,$data,$headers);

        if ($result->code == 0){
            return 555;

        }else{
            return $result->message;
        }

    }


    /**
     * 获取会议站邮件模板详情
     * @return [type] [description]
     */
    public function emailDetails($id,$token)
    {
        //获取数据
        $url = '/v1/site/emails/'.$id;

        //设置headers头
        $headers = getheader($token);

        $res = array();
        //$res['id'] = $id;
        //请求接口信息
        $result = $this->get($url,$res,$headers);

        if ($result->code == 0){
            return $result->data->item;
        }else{
            return $result->message;
        }

    }


    /**
     * 会议站邮件模板更新
     * @return [type] [description]
     */
    public function emailUpdate($id,$data,$token)
    {
        if($data) {
            //获取数据
            $url = '/v1/site/emails/'.$id;

            //设置headers头
            $headers = getheader($token);

            //请求接口信息
            $result = $this->put($url,$data,$headers);

            if ($result->code == 0){
                return 555;
            }else{
                return $result->message;
            }
        }

    }


    /**
     * 会议站邮件模板删除
     * @return [type] [description]
     */
    public function emailDelete($id,$token)
    {
        //获取数据
        $url = '/v1/site/emails/'.$id;

        //设置headers头
        $headers = getheader($token);

        $res = array();
        //$res['id'] = $id;
        //请求接口信息
        $result = $this->delete($url,$res,$headers);

        if ($result->code == 0){
            return 555;
        }else{
            return $result->message;
        }
    }


    /**
     * 会议站邮件模板删除（单独删除中文或者英文）
     * @return [type] [description]
     */
    public function emailDeleteOne($id,$token,$lang)
    {
        //获取数据
        $url = '/v1/site/emails/'.$id.'/translations/'.$lang;

        //设置headers头
        $headers = getheader($token);

        $res = array();
        //$res['id'] = $id;
        //请求接口信息
        $result = $this->delete($url,$res,$headers);

        if ($result->code == 0){
            return 555;
        }else{
            return $result->message;
        }
    }


}